package com.beep.erp.model.addinstock;

import android.content.Intent;
import android.support.v7.widget.AppCompatButton;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.beep.erp.R;
import com.beep.erp.common.base.ToolbarActivity;
import com.beep.erp.common.bean.BizStorageLocationsListBean;
import com.beep.erp.common.bean.StockListBean;
import com.beep.erp.common.utils.ToastUtils;
import com.beep.erp.common.utils.ToolsUtils;
import com.beep.erp.common.widget.ClearEditText;
import com.beep.erp.common.widget.popwindow.SelectDatePop;
import com.beep.erp.common.widget.refresh.RefreshView;
import com.beep.erp.model.stockdetail.StockDetailContract;
import com.beep.erp.model.stockdetail.StockDetailModel;
import com.beep.erp.model.stockdetail.StockDetailPresenter;
import com.beep.erp.model.stockdetail.StockListAdapter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 选择商品  数量
 */
public class EditStockActivity extends ToolbarActivity<StockDetailPresenter, StockDetailModel> implements StockDetailContract.View, RefreshView.OnFreshListener,
        StockListAdapter.OnItemClickLitener {

    public static final String KEY_GOODS_NUM = "goodsNum";//商品数量
    public static final String KEY_GOODS_LIFE = "goodsLife";//商品保质期
    public static final String KEY_GOODS_PRODUCT_DATE = "goodsProductDate";//商品生产日期

    @BindView(R.id.et_product_num)
    ClearEditText etProductNum;
    @BindView(R.id.tv_product_date)
    TextView tvProductDate;
    @BindView(R.id.ll_product_date)
    LinearLayout llProductDate;
    @BindView(R.id.et_life)
    ClearEditText etLife;
    @BindView(R.id.btn_save)
    AppCompatButton btnSave;

    @Override
    protected boolean isBack() {
        return true;
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_edit_instock;
    }

    @Override
    protected void initView() {
        getTvTitle().setText(R.string.add_instock);


    }

    @OnClick({R.id.btn_save, R.id.ll_product_date})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_product_date:
                hideSoftKeyboard();
                SelectDatePop selectDatePop = new SelectDatePop(this,
                        tvProductDate,
                        "");
                selectDatePop.setOnClickOK((year, month, day) -> {
                            tvProductDate.setText(year + "年" + month + "月" + day + "日");
                        }
                );
                break;
            case R.id.btn_save:
                String goodsNum = etProductNum.getText().toString();
                String life = etLife.getText().toString();
                String productDate = tvProductDate.getText().toString();
                if (ToolsUtils.isEmpty(goodsNum)) {
                    ToastUtils.showShort("商品数量不能为空");
                    return;
                }
                if (ToolsUtils.isEmpty(life)) {
                    ToastUtils.showShort("商品保质期不能为空");
                    return;
                }
                if (ToolsUtils.isEmpty(productDate)) {
                    ToastUtils.showShort("商品生产日期不能为空");
                    return;
                }
                Intent intent = new Intent();
                intent.putExtra(KEY_GOODS_NUM, goodsNum);
                intent.putExtra(KEY_GOODS_LIFE, life);
                intent.putExtra(KEY_GOODS_PRODUCT_DATE, productDate);
                setResult(RESULT_OK, intent);

                finish();
                break;
        }
    }

    @Override
    public void getDate() {
    }


    @Override
    public void getStockDetail(StockListBean stockListBean) {
    }

    @Override
    public void getBizStorageLocationList(BizStorageLocationsListBean bizStorageLocationsListBean) {

    }

    @Override
    public void saveInstock() {

    }

    @Override
    public void showLoading() {
    }

    @Override
    public void hideLoading() {
    }

    @Override
    public void showMessage(String message) {
        ToastUtils.showShort(message);
    }

    //刷新
    @Override
    public void onRefresh() {
        getDate();
    }

    @Override
    public void onLoadmore() {

    }

    @Override
    public void onItemClick(View view, int position) {

    }
}
